<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="用户名">
      <el-input v-model="form.email" placeholder="邮箱/手机号"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="form.password" placeholder="数字/字符/特殊符号" type="password"></el-input>
    </el-form-item>
    <el-form-item label="确认密码">
      <el-input v-model="form.confirm_password" placeholder="请再次输入" type="password"></el-input>
    </el-form-item>
    <!-- <el-form-item>
       <el-checkbox v-model="checked">同意注册协议</el-checkbox>
     </el-form-item>-->
    <div style="text-align: center">
      <el-button type="primary" @click="onSubmit" :loading="button_loading">注册</el-button>
    </div>
  </el-form>
</template>
<script>
  /* eslint-disable spaced-comment */

  import { UserRegister } from '@/public/api'

  export default {
    data () {
      return {
        button_loading: false,
        checked: false,
        formLabelWidth: '120px',
        form: {
          email: '',
          password: '',
          confirm_password: ''
        }
      }
    },
    methods: {
      onSubmit () {
        /* if (!this.checked) {
           return this.$message.warning(`请同意用户注册协议`)
         }*/
        if (this.form.password !== this.form.confirm_password) {
          return this.$message.warning(`您输入的密码不一致`)
        }
        this.button_loading = true
        UserRegister({
          email: this.form.email,
          password: this.form.password
        }).then(data => {
          this.button_loading = false
          if (data.status) {
            console.log(data)
            this.$emit('close')
            this.$message.success(`注册成功，请登陆`)
          } else {
//            this.$message.error(`错误`)
            this.$message.error(`请确保邮箱唯一`)
          }
        }).catch(
          message => {
            this.button_loading = false
//            this.$message.error(`服务器错误`)
            this.$message.error(`请确保邮箱唯一`)
          }
        )
      }
    }
  }
</script>
<style>

</style>
